package com.moco.launcher.adapter;

import java.util.ArrayList;
import java.util.List;

import com.moco.launcher.bean.MOCO_CONSTANTS;
import com.moco.launcher.bean.MocoItemInfo;
import com.moco.launcher.play.MusicItemInfo;
import com.oazon.moco.bean.Metadata;
import com.oazon.moco.bean.Metadata.Res;
import com.oazon.moco.bean.ObjectClassType;
import com.oazon.moco.lan.core.http.bean.SongInfo;
import com.oazon.moco.lan.core.http.bean.URIMetaData;
import com.oazon.moco.lan.core.http.bean.UriToQueue;
import com.oazon.moco.playlist.bean.AbstractMedia;
import com.oazon.moco.playlist.bean.ItemType;
import com.oazon.moco.playlist.bean.MediaBean;
import com.oazon.moco.playlist.bean.MediaCollection;
import com.oazon.moco.playlist.bean.MediaCollectionBean;
import com.oazon.moco.playlist.bean.MediaMetadata;
import com.oazon.moco.playlist.bean.MediaMetadataBean;
import com.oazon.moco.playlist.bean.Property;
import com.oazon.common.util.DataFormat;
import com.oazon.common.Logger;

public class DataAdapter {

	public static Metadata parseMusicItemInfo(MocoItemInfo info) {
		if (info == null) 
			return null;

		Metadata bean = new Metadata();
		try {
			bean.setTitle(info.getTitle());
			bean.setItemID(info.getId());
			bean.setLyricURI(info.getLyric());
			bean.setArtist(info.getArtist());
			bean.setAutoAdd(false);
			Metadata.Res res = new Metadata.Res();
			res.setValue(info.getUrl());
			bean.setRes(res);
			bean.setAlbumArtURI(info.getPicture());
		} catch (Exception e) {
		}

		return bean;
	}

	public static SongInfo parseMusicItemInfo(MusicItemInfo musicItemInfo) {
		if (musicItemInfo == null)
			return null;

		SongInfo info = new SongInfo();
		try {
			info.setArtist(musicItemInfo.getArtist());
			info.setId(musicItemInfo.getId());
			info.setLike(musicItemInfo.getLike() >= 0 ? true : false);
			info.setLyric(musicItemInfo.getLyric());
			info.setMimeType("");
			info.setName(musicItemInfo.getTitle());
			info.setPic(musicItemInfo.getPicture());
			info.setUrl(musicItemInfo.getUrl());
		} catch (Exception e) {
		}

		return info;
	}

	public static MusicItemInfo dateAdapator(MediaBean bean) {
		if (bean == null)
			return null;

		MusicItemInfo info = new MusicItemInfo();
		try {
			info.setArtist(bean.getArtist());
			info.setId(bean.getId());
			info.setIsLike(bean.isFavorite() ? 1 : 0);
			info.setLength(Integer.parseInt(String.valueOf(bean.getDuration())));
			info.setUrl(bean.getMusicUrl());
			info.setPicture(bean.getImageUri());
			info.setTitle(bean.getName());
		} catch (Exception e) {
		}

		return info;
	}

	public static MusicItemInfo dateAdapator(Metadata bean) {
		if (bean == null)
			return null;
		
		MusicItemInfo info = new MusicItemInfo();

		info.setArtist(bean.getArtist());
		info.setId(bean.getItemID());
		try {
			String duration = bean.getRes().getDuration();
			info.setLength((int)DataFormat.valueOfdate(duration));
		} catch (Exception e) {
		}

		if (bean.getRes() != null) {
			info.setUrl(bean.getRes().getValue());
		}

		info.setPicture(bean.getAlbumArtURI());
		info.setTitle(bean.getTitle());

		return info;
	}

	public static Metadata dateAdapator(MusicItemInfo info) {
		if (info == null)
			return null;
		
		Metadata bean = new Metadata();
		try {
			bean.setTitle(info.getTitle());
			bean.setItemID(info.getId());
			bean.setLyricURI(info.getLyric());
			bean.setArtist(info.getArtist());
			bean.setAutoAdd(false);
			Metadata.Res res = new Metadata.Res();
			res.setDuration(DataFormat.formatDuring(info.getLength()));
			res.setValue(info.getUrl());
			bean.setRes(res);
			bean.setAlbumArtURI(info.getPicture());
		} catch (Exception e) {
		}

		return bean;
	}

	public static Metadata dateAdapator(MediaMetadata mediaMetadata,
			String parentID, String sid) {
		if (mediaMetadata == null)
			return null;

		Metadata bean = new Metadata();
		Res res = new Res();
		try {
			if (mediaMetadata.getItemType() == ItemType.TRACK) {
				if (mediaMetadata.getTrackMetadata() != null) {
					if (mediaMetadata.getTrackMetadata().getAlbum() != null) {
						bean.setAlbum(mediaMetadata.getTrackMetadata()
								.getAlbum());
					}
					if (mediaMetadata.getTrackMetadata().getAlbumArtURI() != null) {
						bean.setAlbumArtURI(mediaMetadata.getTrackMetadata()
								.getAlbumArtURI());
					}
					if (mediaMetadata.getTrackMetadata().getAlbumArtist() != null) {
						bean.setArtist(mediaMetadata.getTrackMetadata()
								.getAlbumArtist());
					}
					if (mediaMetadata.getTrackMetadata().getDuration() != null) {
						if (mediaMetadata.getTrackMetadata().getDuration() <= 2000) {
							res.setDuration(DataFormat
									.formatDuring(mediaMetadata
											.getTrackMetadata().getDuration() * 1000));
						} else {
							res.setDuration(DataFormat
									.formatDuring(mediaMetadata
											.getTrackMetadata().getDuration()));
						}

					}
					if (mediaMetadata.getTrackMetadata().getArtist() != null) {
						bean.setArtist(mediaMetadata.getTrackMetadata()
								.getArtist());
					}

				}

				bean.setAutoAdd(false);
				bean.setCreator("");
				if (mediaMetadata.getId() != null) {
					bean.setId(mediaMetadata.getId());
					bean.setItemID(mediaMetadata.getId());
				}

				bean.setLyricURI("");
				bean.setObjectClass(ObjectClassType.MUSIC_TRACK);
				if (parentID != null) {
					bean.setParentID(parentID);
				}
				bean.setRadioShowMd("");

				if (mediaMetadata.getMimeType() != null) {
					res.setProtocolInfo("http:" + mediaMetadata.getMimeType());
				}
				String value = null;
				if (mediaMetadata.getId() != null && !MOCO_CONSTANTS.RECOMMEND_ROOT.equals(sid)) {
					value = "x-o2-http:" + mediaMetadata.getId() + "?sid="
							+ sid;
				} else {
					value = "x-o2-http:" + mediaMetadata.getId()+"?sid="
							+ MOCO_CONSTANTS.RECOMMEND_ROOT;
				}
				if (sid != null) {
					if (MOCO_CONSTANTS.RECOMMEND_ROOT.equals(sid)) {
						bean.setServiceID(MOCO_CONSTANTS.RECOMMEND_ROOT);
					} else {
						bean.setServiceID(sid);
					}
				}else{
					bean.setServiceID(MOCO_CONSTANTS.RECOMMEND_ROOT);
					value = "x-o2-http:" + mediaMetadata.getId()+"?sid="
							+ MOCO_CONSTANTS.RECOMMEND_ROOT;
				}
				res.setValue(value);
				bean.setRes(res);
				bean.setRestricted(true);
				bean.setStreamContent("");
				if (mediaMetadata.getTitle() != null) {
					bean.setTitle(mediaMetadata.getTitle());
				}
				try {
					List<Property> properties = mediaMetadata.getDynamic()
							.getProperty();
					for (Property property : properties) {
						if (property.getName().equals("isLoved")) {
							bean.setFavorite(Integer.valueOf(property
									.getValue().toString()) != 0);
						}
					}
				} catch (Exception e) {
					bean.setFavorite(false);
				}
				bean.setCanAddToFavorites(bean.isCanAddToFavorites());
			}

		} catch (Exception e) {
			Logger.e("Exception",
					"com.moco.launcher.adapter.DataAdapter.dateAdapator");
		}

		return bean;
	}

	public static Metadata dateAdapator(UriToQueue.Instance instance) {
		if (instance == null) {
			return null;
		}
		Metadata bean = new Metadata();
		Res res = new Res();
		if (instance.getEnqueuedItemID() != null) {
			bean.setId(instance.getEnqueuedItemID());
			bean.setItemID(instance.getEnqueuedItemID());
		}

		if (instance.getEnqueuedServiceID() != null) {
			bean.setServiceID(instance.getEnqueuedServiceID());
		}
		if (instance.getEnqueuedURI() != null) {
			res.setValue(instance.getEnqueuedURI());
		} else {
			try {
				res.setValue("x-o2-http:" + instance.getEnqueuedItemID()
						+ "?sid=" + instance.getEnqueuedServiceID());
			} catch (Exception e) {
			}

		}
		URIMetaData uriMetaData = instance.getEnqueuedURIMetaData();
		if (uriMetaData != null) {
			bean.setRestricted(uriMetaData.isRestricted());
			if (uriMetaData.getAlbum() != null) {
				bean.setAlbum(uriMetaData.getAlbum());
			}
			if (uriMetaData.getAlbumArtURI() != null) {
				bean.setAlbumArtURI(uriMetaData.getAlbumArtURI());
			}
			if (uriMetaData.getArtist() != null) {
				bean.setArtist(uriMetaData.getArtist());
			}
			if (uriMetaData.getCreator() != null) {
				bean.setCreator(uriMetaData.getCreator());
			}
			if (uriMetaData.getDuration() != null) {
				res.setDuration(uriMetaData.getDuration());
			}
			if (uriMetaData.getItemID() != null) {

			}
			if (uriMetaData.getLyricURI() != null) {
				bean.setLyricURI(uriMetaData.getLyricURI());
			}
			if (uriMetaData.getMimeType() != null) {
				res.setProtocolInfo("http:" + uriMetaData.getMimeType());
			}
			if (uriMetaData.getParentID() != null) {
				bean.setParentID(uriMetaData.getParentID());
			}
			if (uriMetaData.getObjectClass() != null) {
				bean.setObjectClass(uriMetaData.getObjectClass());
			}
			if (uriMetaData.getTitle() != null) {
				bean.setTitle(uriMetaData.getTitle());
			}

		}
		instance.getInstanceID();

		bean.setRes(res);
		return bean;
	}

	public static List<Metadata> paseMetadatas(List<AbstractMedia> item,
			String parentID, String sid) {
		List<Metadata> metaDatas = new ArrayList<Metadata>();
		for (AbstractMedia abstractMedia : item) {
			try {
				metaDatas.add(DataAdapter.dateAdapator(
						(MediaMetadata) abstractMedia, parentID, sid));
			} catch (Exception e) {
				return null;
			}
		}
		return metaDatas;
	}


	
	
	public static MediaMetadata paseMediaMetadataBean(
			MediaMetadataBean mediaMetadataBean) {
		MediaMetadata mediaMetadata = new MediaMetadata();
		try {
			if (mediaMetadata == null) {
				return null;
			}
			
			if (mediaMetadataBean.getId() != null) {
				mediaMetadata.setId(mediaMetadataBean.getId());
			}
			
			if (mediaMetadataBean.getItemType() != null) {
				mediaMetadata.setItemType(mediaMetadataBean.getItemType());
			}
			
			if (mediaMetadataBean.getTitle() != null) {
				mediaMetadata.setTitle(mediaMetadataBean.getTitle());
			}
			
			if (mediaMetadataBean.getMimeType() != null) {
				mediaMetadata.setMimeType(mediaMetadataBean.getMimeType());
			}
			
			if (mediaMetadataBean.getStreamMetadata() != null) {
				if (mediaMetadataBean.getStreamMetadata().getCurrentHost() != null) {
					mediaMetadata.getStreamMetadata().setCurrentHost(mediaMetadataBean.getStreamMetadata().getCurrentHost());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getCurrentShowId() != null) {
					mediaMetadata.getStreamMetadata().setCurrentShowId(mediaMetadataBean.getStreamMetadata().getCurrentShowId());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getCurrentShow() != null) {
					mediaMetadata.getStreamMetadata().setCurrentShow(mediaMetadataBean.getStreamMetadata().getCurrentShow());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getSecondsRemaining() != null) {
					mediaMetadata.getStreamMetadata().setSecondsRemaining(mediaMetadataBean.getStreamMetadata().getSecondsRemaining());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getSecondsToNextShow() != null) {
					mediaMetadata.getStreamMetadata().setSecondsToNextShow(mediaMetadataBean.getStreamMetadata().getSecondsToNextShow());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getBitrate() != null) {
					mediaMetadata.getStreamMetadata().setBitrate(mediaMetadataBean.getStreamMetadata().getBitrate());
				}
				
				if (mediaMetadataBean.getStreamMetadata().getLogo() != null) {
					mediaMetadata.getStreamMetadata().setLogo(mediaMetadataBean.getStreamMetadata().getLogo());
				}
			}

			if (mediaMetadataBean.getTrackMetadata() != null) {
				if (mediaMetadataBean.getTrackMetadata().getArtist() != null) {
					mediaMetadata.getTrackMetadata().setArtist(mediaMetadataBean.getTrackMetadata().getArtist());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getArtistId() != null) {
					mediaMetadata.getTrackMetadata().setArtistId(mediaMetadataBean.getTrackMetadata().getArtistId());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getComposerId() != null) {
					mediaMetadata.getTrackMetadata().setComposerId(mediaMetadataBean.getTrackMetadata().getComposerId());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getComposer() != null) {
					mediaMetadata.getTrackMetadata().setComposer(mediaMetadataBean.getTrackMetadata().getComposer());
				}
				
				
				if (mediaMetadataBean.getTrackMetadata().getAlbumId() != null) {
					mediaMetadata.getTrackMetadata().setAlbumId(mediaMetadataBean.getTrackMetadata().getAlbumId());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getAlbum() != null) {
					mediaMetadata.getTrackMetadata().setAlbum(mediaMetadataBean.getTrackMetadata().getAlbum());
				}
				
				
				if (mediaMetadataBean.getTrackMetadata().getAlbumArtistId() != null) {
					mediaMetadata.getTrackMetadata().setAlbumArtistId(mediaMetadataBean.getTrackMetadata().getAlbumArtistId());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getAlbumArtist() != null) {
					mediaMetadata.getTrackMetadata().setAlbumArtist(mediaMetadataBean.getTrackMetadata().getAlbumArtist());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getGenreId() != null) {
					mediaMetadata.getTrackMetadata().setGenreId(mediaMetadataBean.getTrackMetadata().getGenreId());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getGenre() != null) {
					mediaMetadata.getTrackMetadata().setGenre(mediaMetadataBean.getTrackMetadata().getGenre());
				}
				
				if (mediaMetadataBean.getTrackMetadata().getDuration() != null) {
					mediaMetadata.getTrackMetadata().setDuration(mediaMetadataBean.getTrackMetadata().getDuration());
				}
				if (mediaMetadataBean.getTrackMetadata().getRating() != null) {
					mediaMetadata.getTrackMetadata().setRating(mediaMetadataBean.getTrackMetadata().getRating());
				}
				if (mediaMetadataBean.getTrackMetadata().getAlbumArtURI() != null) {
					mediaMetadata.getTrackMetadata().setAlbumArtURI(mediaMetadataBean.getTrackMetadata().getAlbumArtURI());
				}
				if (mediaMetadataBean.getTrackMetadata().isCanPlay() != null) {
					mediaMetadata.getTrackMetadata().setCanPlay(mediaMetadataBean.getTrackMetadata().isCanPlay());
				}
				if (mediaMetadataBean.getTrackMetadata().isCanSkip()!= null) {
					mediaMetadata.getTrackMetadata().setCanSkip(mediaMetadataBean.getTrackMetadata().isCanSkip());
				}
				if (mediaMetadataBean.getTrackMetadata().isCanAddToFavorites() != null) {
					mediaMetadata.getTrackMetadata().setCanAddToFavorites(mediaMetadataBean.getTrackMetadata().isCanAddToFavorites());
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return mediaMetadata;
	}
	public static MediaMetadataBean paseMediaMetadata(
			MediaMetadata mediaMetadata,String parentId, String provider) {
		MediaMetadataBean bean = new MediaMetadataBean();
		try {
			if (mediaMetadata == null)
				return null;
			if (mediaMetadata.getId() != null) {
				bean.setId(mediaMetadata.getId());
			}
			
			if (mediaMetadata.getItemType() != null) {
				bean.setItemType(mediaMetadata.getItemType());
			}
			
			if (mediaMetadata.getTitle() != null) {
				bean.setTitle(mediaMetadata.getTitle());
			}
			
			if (mediaMetadata.getMimeType() != null) {
				bean.setMimeType(mediaMetadata.getMimeType());
			}
			
			if(parentId != null){
				bean.setParentId(parentId);
			}
			if(provider != null){
				bean.setProvider(provider);
			}
			
			if (mediaMetadata.getStreamMetadata() != null) {
				if (mediaMetadata.getStreamMetadata().getCurrentHost() != null) {
					bean.getStreamMetadata().setCurrentHost(mediaMetadata.getStreamMetadata().getCurrentHost());
				}
				
				if (mediaMetadata.getStreamMetadata().getCurrentShowId() != null) {
					bean.getStreamMetadata().setCurrentShowId(mediaMetadata.getStreamMetadata().getCurrentShowId());
				}
				
				if (mediaMetadata.getStreamMetadata().getCurrentShow() != null) {
					bean.getStreamMetadata().setCurrentShow(mediaMetadata.getStreamMetadata().getCurrentShow());
				}
				
				if (mediaMetadata.getStreamMetadata().getSecondsRemaining() != null) {
					bean.getStreamMetadata().setSecondsRemaining(mediaMetadata.getStreamMetadata().getSecondsRemaining());
				}
				
				if (mediaMetadata.getStreamMetadata().getSecondsToNextShow() != null) {
					bean.getStreamMetadata().setSecondsToNextShow(mediaMetadata.getStreamMetadata().getSecondsToNextShow());
				}
				
				if (mediaMetadata.getStreamMetadata().getBitrate() != null) {
					bean.getStreamMetadata().setBitrate(mediaMetadata.getStreamMetadata().getBitrate());
				}
				
				if (mediaMetadata.getStreamMetadata().getLogo() != null) {
					bean.getStreamMetadata().setLogo(mediaMetadata.getStreamMetadata().getLogo());
				}
			}
			
			if (mediaMetadata.getTrackMetadata() != null) {
				if (mediaMetadata.getTrackMetadata().getArtist() != null) {
					bean.getTrackMetadata().setArtist(mediaMetadata.getTrackMetadata().getArtist());
				}
				
				if (mediaMetadata.getTrackMetadata().getArtistId() != null) {
					bean.getTrackMetadata().setArtistId(mediaMetadata.getTrackMetadata().getArtistId());
				}
				
				if (mediaMetadata.getTrackMetadata().getComposerId() != null) {
					bean.getTrackMetadata().setComposerId(mediaMetadata.getTrackMetadata().getComposerId());
				}
				
				if (mediaMetadata.getTrackMetadata().getComposer() != null) {
					bean.getTrackMetadata().setComposer(mediaMetadata.getTrackMetadata().getComposer());
				}
				
				
				if (mediaMetadata.getTrackMetadata().getAlbumId() != null) {
					bean.getTrackMetadata().setAlbumId(mediaMetadata.getTrackMetadata().getAlbumId());
				}
				
				if (mediaMetadata.getTrackMetadata().getAlbum() != null) {
					bean.getTrackMetadata().setAlbum(mediaMetadata.getTrackMetadata().getAlbum());
				}
				
				
				if (mediaMetadata.getTrackMetadata().getAlbumArtistId() != null) {
					bean.getTrackMetadata().setAlbumArtistId(mediaMetadata.getTrackMetadata().getAlbumArtistId());
				}
				
				if (mediaMetadata.getTrackMetadata().getAlbumArtist() != null) {
					bean.getTrackMetadata().setAlbumArtist(mediaMetadata.getTrackMetadata().getAlbumArtist());
				}
				
				if (mediaMetadata.getTrackMetadata().getGenreId() != null) {
					bean.getTrackMetadata().setGenreId(mediaMetadata.getTrackMetadata().getGenreId());
				}
				
				if (mediaMetadata.getTrackMetadata().getGenre() != null) {
					bean.getTrackMetadata().setGenre(mediaMetadata.getTrackMetadata().getGenre());
				}
				
				if (mediaMetadata.getTrackMetadata().getDuration() != null) {
					bean.getTrackMetadata().setDuration(mediaMetadata.getTrackMetadata().getDuration());
				}
				if (mediaMetadata.getTrackMetadata().getRating() != null) {
					bean.getTrackMetadata().setRating(mediaMetadata.getTrackMetadata().getRating());
				}
				if (mediaMetadata.getTrackMetadata().getAlbumArtURI() != null) {
					bean.getTrackMetadata().setAlbumArtURI(mediaMetadata.getTrackMetadata().getAlbumArtURI());
				}
				if (mediaMetadata.getTrackMetadata().isCanPlay() != null) {
					bean.getTrackMetadata().setCanPlay(mediaMetadata.getTrackMetadata().isCanPlay());
				}
				if (mediaMetadata.getTrackMetadata().isCanSkip()!= null) {
					bean.getTrackMetadata().setCanSkip(mediaMetadata.getTrackMetadata().isCanSkip());
				}
				if (mediaMetadata.getTrackMetadata().isCanAddToFavorites() != null) {
					bean.getTrackMetadata().setCanAddToFavorites(mediaMetadata.getTrackMetadata().isCanAddToFavorites());
				}
			}
			
		} catch (Exception e) {
			
		}
		return bean;
	}
	
	
	public static MediaCollection paseMediaCollectionBean(
			MediaCollectionBean mediaCollectionBean) {
		MediaCollection collection = new MediaCollection();
		try {
			if (mediaCollectionBean == null) {
				return null;
			}

			if (mediaCollectionBean.getAlbumArtURI() != null) {
				collection.setAlbumArtURI(mediaCollectionBean.getAlbumArtURI());
			}
			if (mediaCollectionBean.getArtist() != null) {
				collection.setArtist(mediaCollectionBean.getArtist());
			}
			if (mediaCollectionBean.getArtistId() != null) {
				collection.setArtistId(mediaCollectionBean.getArtistId());
			}
			if (mediaCollectionBean.getAuthRequired() != null) {
				collection.setAuthRequired(mediaCollectionBean
						.getAuthRequired());
			}
			if (mediaCollectionBean.getCanAddToFavorite() != null) {
				collection.setCanAddToFavorite(mediaCollectionBean
						.getCanAddToFavorite());
			}
			if (mediaCollectionBean.getCanAddToFavorites() != null) {
				collection.setCanAddToFavorites(mediaCollectionBean
						.getCanAddToFavorites());
			}
			if (mediaCollectionBean.getCanCache() != null) {
				collection.setCanCache(mediaCollectionBean.getCanCache());
			}
			if (mediaCollectionBean.getCanEnumerate() != null) {
				collection.setCanEnumerate(mediaCollectionBean
						.getCanEnumerate());
			}
			if (mediaCollectionBean.getCanPlay() != null) {
				collection.setCanPlay(mediaCollectionBean.getCanPlay());
			}
			if (mediaCollectionBean.getCanScroll() != null) {
				collection.setCanScroll(mediaCollectionBean.getCanScroll());
			}
			if (mediaCollectionBean.getCanSkip() != null) {
				collection.setCanSkip(mediaCollectionBean.getCanSkip());
			}
			if (mediaCollectionBean.getHomogeneous() != null) {
				collection.setHomogeneous(mediaCollectionBean.getHomogeneous());
			}
			if (mediaCollectionBean.getId() != null) {
				collection.setId(mediaCollectionBean.getId());
			}
			if (mediaCollectionBean.getItemType() != null) {
				collection.setItemType(mediaCollectionBean.getItemType());
			}
			if (mediaCollectionBean.getReadOnly() != null) {
				collection.setReadOnly(mediaCollectionBean.getReadOnly());
			}
			if (mediaCollectionBean.getTitle() != null) {
				collection.setTitle(mediaCollectionBean.getTitle());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		return collection;
	}
	
	
	public static MediaCollectionBean parseMediaCollection(
			MediaCollection mediaCollection,String parentId, String provider) {
		MediaCollectionBean bean = new MediaCollectionBean();
		try {
			if (mediaCollection == null)
				return null;

			if (mediaCollection.getAlbumArtURI() != null)
				bean.setAlbumArtURI(mediaCollection.getAlbumArtURI());

			if (mediaCollection.getArtist() != null) 
				bean.setArtist(mediaCollection.getArtist());

			if (mediaCollection.getArtistId() != null) 
				bean.setArtistId(mediaCollection.getArtistId());

			if (mediaCollection.isAuthRequired() != null) 
				bean.setAuthRequired(mediaCollection.isAuthRequired());
			
			if (mediaCollection.isCanAddToFavorite() != null)
				bean.setCanAddToFavorite(mediaCollection.isCanAddToFavorite());
			
			if (mediaCollection.isCanAddToFavorites() != null)
				bean.setCanAddToFavorites(mediaCollection.isCanAddToFavorites());

			if (mediaCollection.isCanCache() != null) 
				bean.setCanCache(mediaCollection.isCanCache());

			if (mediaCollection.isCanEnumerate() != null)
				bean.setCanEnumerate(mediaCollection.isCanEnumerate());

			if (mediaCollection.isCanPlay() != null)
				bean.setCanPlay(mediaCollection.isCanPlay());

			if (mediaCollection.isCanScroll() != null) 
				bean.setCanScroll(mediaCollection.isCanScroll());

			if (mediaCollection.isCanSkip() != null) 
				bean.setCanSkip(mediaCollection.isCanSkip());

			if (mediaCollection.isHomogeneous() != null) 
				bean.setHomogeneous(mediaCollection.isHomogeneous());

			if (mediaCollection.getId() != null) 
				bean.setId(mediaCollection.getId());

			if (mediaCollection.getItemType() != null) 
				bean.setItemType(mediaCollection.getItemType());

			bean.setReadOnly(mediaCollection.isReadOnly());
			if (mediaCollection.getTitle() != null)
				bean.setTitle(mediaCollection.getTitle());

			if(parentId != null)
				bean.setParentId(parentId);

			if(provider != null)
				bean.setProvider(provider);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return bean;
	}
}
